<?php


namespace App\Admin\Controllers;

use SmallRuralDog\Admin\Components\Grid\Tag;
use SmallRuralDog\Admin\Controllers\AdminController;
use SmallRuralDog\Admin\Grid;
use App\Models\Delivery;

class DeliveryController extends AdminController
{

    public function grid()
    {
        $grid = new Grid(new Delivery());

        $grid->defaultSort('delivery_id', 'desc');

        $grid->column('delivery_id', "发货单单编号")->width(150)->sortable();

        $grid->column('order_bn', "订单编号")->width(150)->sortable();

        $grid->column('member.nickname', '会员')->width(120);

        $grid->column('type', "类型")->width(100)->align("center")->customValue(function ($row, $value) {
            $source = ['delivery'=>'发货', 'return'=>'退货'];
            return $source[$value];
        })->component(Tag::make()->type(["发货" => "success", "退货" => "danger"]));

        $grid->column('status', "状态")->width(100)->align("center")->customValue(function ($row, $value) {
            $status = ['success'=>'执行成功', 'fail'=>'执行失败'];
            return $status[$value];
        })->component(Tag::make()->type(["执行成功" => "success", "执行失败" => "danger"]));

        $grid->column('detail.goods_name', "发货商品")->width(200)->customValue(function ($row, $value) {
            $v = [];
            foreach($value as $val)
            {
                $v[] = $val;
            }
            $v = implode("<br/><br/>", $v);
            return $v; // 只显示第一张图片
        })->align("center");

        $grid->column('expresscompany.name', '物流公司')->width(150);
        $grid->column('ship_number', '发货单号')->width(150);

        $grid->column('remark', '备注');

        $grid->column('created_at', '时间')->width(150)->sortable();

        // 快速搜索
        $grid->quickSearch(['order_bn']);

        $grid->quickSearchPlaceholder("请输入订单号");

        $grid->actionLabel(''); // 隐藏操作

        $grid->actions(function (Grid\Actions $actions){

            $actions->hideDeleteAction(); // 隐藏删除操作
            $actions->hideEditAction(); // 隐藏编辑操作

        })->toolbars(function (Grid\Toolbars $toolbars)
        {
            $toolbars->hideCreateButton();
        });

        return $grid;
    }

}
